#include <bits/stdc++.h>

#define in read()
#define fi first
#define se second
#define pb push_back
#define rep(i, x, y) for(int i = (x); i <= (y); i++) 
#define per(i, x, y) for(int i = (x); i >= (y); i--)

using namespace std;

using ll = long long;
using db = double;
using pii = pair < int , int >;
using vec = vector < int >;
using veg = vector < pii >;

int read() {
	int x = 0; bool f = 0; char ch = getchar(); while(!isdigit(ch)) f |= ch == '-', ch = getchar(); 
	while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getchar(); return f ? -x : x;
}

const int N = 310;
const int mod = 1e9 + 7;

int f[N][N][N];
int n, m, ans;
veg G[N];

int upd(int x) { return x + (x >> 31 & mod); }

int main() {
#ifndef ONLINE_JUDGE
	freopen("1.in", "r", stdin);
#endif
	n = in; m = in;
	rep(i, 1, m) {
		int l = in, r = in, x = in;
		G[r].pb({ l, x });
	}
	f[0][0][0] = 1;
	auto check = [&](auto x, auto y, auto z) {
		int l = max({ x, y , z });
		for(auto d : G[l]) {
			int cnt = (x >= d.fi) + (y >= d.fi) + (z >= d.fi);
			if(cnt != d.se) return false;
		} return true;
	};
	rep(i, 0, n)
		rep(j, 0, n)
		rep(k, 0, n)
		if(f[i][j][k]) {
	
			if(!check(i, j, k)) { f[i][j][k] = 0; continue; }
			int l = max({ i, j, k }); if(l == n) { ans = upd(ans + f[i][j][k] - mod); continue; }
			f[l + 1][j][k] = upd(f[l + 1][j][k] + f[i][j][k] - mod);
			f[i][l + 1][k] = upd(f[i][l + 1][k] + f[i][j][k] - mod);
			f[i][j][l + 1] = upd(f[i][j][l + 1] + f[i][j][k] - mod);
		}
	printf("%d\n", ans);
	return 0;
}
